<template>
	<view>
		<swiper class="screen-swiper square-dot" :indicator-dots="true" :circular="true" :autoplay="true" interval="5000"
		 duration="500" id="swiper-box">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<image :src="item" mode="aspectFill"></image>
			</swiper-item>
		</swiper>

		<view class="out-border-line" style="padding: 15rpx;">
			<view class="common-width90 flex-column">
				<text class="price-text">￥{{commodity.price}}</text>
				<view class="commodity-stock-box flex-just">
					<text class="commodity-text">{{commodity.name}}</text>
					<text class="stock-text">库存：{{commodity.total}}</text>
				</view>
				<view class="brief-introduction-box">
					<text>{{commodity.description}}</text>
				</view>
			</view>
		</view>

		<view class="bottom-out-box">
			<view class="common-width90 flex-just bottom-in-box">
				<view class="icon-text-box flex-column">
					<image src="/static/corporation/groceryStore/blueshopcar.png" @click="turnShopcar()"></image>
					<!-- <text>购物车</text> -->
				</view>
				<view class="button-group flex-just">
					<button class="button-left" @click="addShoppingCar()">加入购物车</button>
					<button class="button-right">立即订购</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommodityDetail
	} from '@/common/api/groceryStore/groceryStore.js'
	import {
		addShoppingCar
	} from '@/common/api/groceryStore/shopcar.js'
	export default {
		data() {
			return {
				swiperList: [
					'/static/research/user.jpg',
					'/static/corporation/groceryStore/club_logo.jpg',
					'/static/corporation/picture.jpg'
				],
				commodity: {},
				goodsId: 0
			}
		},
		methods: {
			// 获取某样商品的详情
			getCommodityDetail: function(goodsId) {
				getCommodityDetail(goodsId).then(res => {
					if (res.data.code == 200) {
						if (res.data.data != null) {
							this.commodity = res.data.data
						} else {
							uni.showToast({
								title: '暂时没有该数据详情',
								icon: 'none'
							})
						}
					} else {
						uni.showToast({
							title: "网络错误",
							icon: 'none'
						})
					}
				})
			},
			// 添加到购物车
			addShoppingCar: function() {
				// 通过相同的index值遍历商品列表的才能获取是拿的那个
				addShoppingCar({
					goodsId: this.goodsId,
					memberId: uni.getStorageSync("memberId"),
					total: 1
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '成功添加到购物车'
						})
						uni.navigateTo({
							url: '/pagesA/pages/groceryStore/shopingCar/shopingCar'
						})
					} else {
						uni.showToast({
							title: '网络错误',
							icon: 'none'
						})
					}
				})
			},
			//跳转到购物车
			 turnShopcar:function(){
				uni.navigateTo({
					url: '/pagesA/pages/groceryStore/shopingCar/shopingCar'
				}) 
			 },
		},
		onLoad(e) {
			this.getCommodityDetail(e.goodsId)
			this.goodsId = e.goodsId
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
	}

	#swiper-box {
		width: 100%;
		height: 650rpx;
	}

	.price-text {
		font-size: 20px;
		color: red;
	}

	.commodity-stock-box {
		width: 100%;
		height: 70rpx;
	}

	.commodity-text {
		width: 70%;
		font-size: 16px;
		font-weight: bold;
		line-height: 70rpx;
	}

	.stock-text {
		width: 30%;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 14px;
		color: #A5A5A5;
	}

	.brief-introduction-box {
		width: 100%;
		height: 150rpx;
		overflow: auto;
	}

	.brief-introduction-box text {
		width: 100%;
		font-size: 15px;
		color: #676767;
	}

	/* 底部加入购物车 */
	.bottom-out-box {
		width: 100%;
		height: 100rpx;
		border-top: 1px solid #C9C9C9;
		position: fixed;
		bottom: 0;
		background: #FFFFFF;
		z-index: 1;
	}

	.bottom-in-box {
		align-items: center;
	}

	.icon-text-box {
		width: 20%;
		height: 70rpx;
		text-align: center;
	}

	.icon-text-box image {
		width: 70rpx;
		height: 70rpx;
	}

	.icon-text-box text {
		font-size: 14px;
		font-weight: 500;
	}

	.button-group {
		width: 70%;
		height: 60rpx;
	}

	.button-left {
		width: 49%;
		height: 60rpx;
		background: #03BDFB;
		border-radius: 6px 0 0 6px;
		color: #FFFFFF;
		font-size: 14px;
		line-height: 60rpx;
	}

	.button-right {
		width: 49%;
		height: 100%;
		background: #53A4FC;
		border-radius: 0 6px 6px 0;
		color: #FFFFFF;
		font-size: 14px;
		line-height: 60rpx;
	}
</style>
